package lineCounter;


import java.io.File;
import java.util.ArrayList;

import pathManager.PathManager;
import threads.ParlallelThreads;
import threads.SequentialThreads;

public class Main {

	public static void main(String[] args) {
		int argument_number = args.length;
		PathManager manager = PathManager.getManager();
		
		
			if(argument_number != 0){
				manager.setPaths(args);
				
				long timeStart=0, timeStop=0;
				
				System.out.println("czytanie sekwencyjne: ");
				timeStart = System.currentTimeMillis();
				doSequential();
				timeStop = System.currentTimeMillis();
				System.out.println("czas wykonania: "+(timeStop - timeStart) + " milisekund");
				
				timeStart = System.currentTimeMillis();
				doParlallel();
				timeStop = System.currentTimeMillis();
				System.out.println("czas wykonania: "+(timeStop - timeStart) + " milisekund");

			}
			
			
			else {
				System.out.println("Nie podano żadnych argumentów funkcji main, kończę");
			}
	}
	
	
	public static void doSequential(){
		SequentialThreads st = new SequentialThreads();
				st.run();
	}
	
	public static void doParlallel(){
		PathManager manager = PathManager.getManager();
		ArrayList<File> fileList = manager.getFilePaths();
		Thread[] threads = new Thread[manager.getNumberOfFiles()];
			for (int i = 0 ; i < manager.getNumberOfFiles() ; i ++){
				threads[i] = new ParlallelThreads(fileList.get(i));
			}
			for (int i = 0 ; i < manager.getNumberOfFiles() ; i ++){
				threads[i].start();
			}
			
	}

}
